package com.example.eamh2system.netty.handler;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.nio.charset.Charset;

@Slf4j
@ChannelHandler.Sharable
@Component
public class H2NettyServerHandler extends ChannelInboundHandlerAdapter {


    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        log.info("read channel:{}" , ctx.channel());
        ByteBuf byteBuf= (ByteBuf) msg;
        String s = byteBuf.toString(Charset.defaultCharset());
        log.info("收到心跳消息:{}", s);
        String s1="hi,client";
        ByteBuf buf= Unpooled.buffer();
        buf.writeBytes(s1.getBytes());
        ctx.writeAndFlush(buf);

    }




}
